package com.study.demoservice.generics;

import com.study.demoservice.bean.Student;
import com.study.demoservice.bean.dto.PersonRequest;

public class Generics {

    /**
     * 泛型方法
     * @param a 用来创建泛型对象
     * @param <T> 声明一个泛型T
     * @return 创建的泛型对象
     * @throws InstantiationException
     * @throws IllegalAccessException
     */
    public <T> T getObject(Class<T> a) throws InstantiationException, IllegalAccessException {
        return a.newInstance();
    }

    public static void main(String[] args) {
        Generics generics = new Generics();
        Object object = null;
        try {
            object = generics.getObject(Class.forName("com.study.demoservice.bean.Student"));
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println(object instanceof Student);
        Student student = (Student) object;
        student.setId("1");
        student.setName("222");
        System.out.println(student);
    }

}
